package com.sms.web.rest;

import java.io.Serializable;

/**
 * @desc restfull返回对象
 * @author WuJiangWu
 * @date 2018年7月21日上午1:22:08
 */
public class RestObject implements Serializable {
    
    private static final long serialVersionUID = -7771374323162062273L;
    
    /** 状态码成功 */
    public final static int STATUS_CODE_SUCCESS = 0;
    
    /** 状态调用失败 */
    public final static int STATUS_CODE_FAILURE = 300;
    
    /** 状态码超时 */
    public final static int STATUS_CODE_TIMEOUT = 301;

    /** 状态码禁止访问 */
    public final static int STATUS_CODE_NOT_LOGIN = 401;
    
    /** 状态码权限不够禁止访问 */
    public final static int STATUS_CODE_FORBIDDEN = 403;
    
    /** 状态码未找到 */
    public final static int STATUS_CODE_NOTFOUND = 404;
    
    /** 状态码服务器端错误 */
    public final static int STATUS_CODE_SERVEERROR = 500;
    
    /**  参数错误 */
    public final static int STATUS_PARAMS_ERROR = 1000;
    
    /****** 密码错误！ ******/
    public final static int STATUS_LOGIN_INCORRECTCREDENTIALS = 1001;
    
    /****** 验证码错误！ ******/
    public final static int STATUS_LOGIN_CAPTCHA = 1003;
    
    /****** 认证失败！ ******/
    public final static int STATUS_LOGIN_AUTHENTICATION = 1004;
    
    /****** 账号被冻结！ ******/
    public final static int STATUS_LOGIN_DISABLEDACCOUNT = 1005;
    
    
    /** 返回状态 */
    private int state = STATUS_CODE_SUCCESS;
    
    /** 成功后的默认消息 */
    private final static String SUCCESS_MESSAGE = "success";
    
    /** 消息 */
    private String message = "";
    
    /** 返回数据 */
    private Object data = "";
    
    /**
     * 生成成功对象
     * 
     * @param message message
     * @return obj
     */
    public static RestObject newOk() {
        return new RestObject(STATUS_CODE_SUCCESS, "success");
    }
    
    /**
     * 生成成功对象
     * 
     * @param message message
     * @return obj
     */
    public static RestObject newOk(String message) {
        return new RestObject(STATUS_CODE_SUCCESS, message);
    }
    
    /**
     * 生成成功对象
     * 
     * @param message message
     * @param data data
     * @return obj
     */
    public static RestObject newOk(String message, Object data) {
        return new RestObject(STATUS_CODE_SUCCESS, message, data);
    }
    
    /**
     * 生成成功对象
     * 
     * @param data data
     * @return obj
     */
    public static RestObject newOk(Object data) {
        return new RestObject(STATUS_CODE_SUCCESS, SUCCESS_MESSAGE, data);
    }
    
    /**
     * 生成错误对象
     * 
     * @param message message
     * @return obj
     */
    public static RestObject newError(String message) {
        return new RestObject(STATUS_CODE_FAILURE, message);
    }
    
    /**
     * 生成错误对象
     * 
     * @param message message
     * @param data data
     * @return obj
     */
    public static RestObject newError(String message, Object data) {
        return new RestObject(STATUS_CODE_FAILURE, message, data);
    }
    
    /**
     * 生成参数错误对象
     * 
     * @param message message
     * @return obj
     */
    public static RestObject newParamsError(String message) {
        return new RestObject(STATUS_PARAMS_ERROR, message);
    }
    
    /**
     * 生成超时对象
     * @param message message
     * @return obj
     */
    public static RestObject newTimeout(String message) {
        return new RestObject(STATUS_CODE_TIMEOUT, message);
    }
    
    /**
     * 生成超时对象
     * @param message message
     * @param data data
     * @return obj
     */
    public static RestObject newTimeout(String message, Object data) {
        return new RestObject(STATUS_CODE_TIMEOUT, message, data);
    }
    
    /**
     * 生成禁止访问对象
     * @param message message
     * @return obj
     */
    public static RestObject newForbidden(String message) {
        return new RestObject(STATUS_CODE_TIMEOUT, message);
    }
    
    /**
     * 生成禁止访问对象
     * @param message message
     * @param data data
     * @return obj
     */
    public static RestObject newForbidden(String message, Object data) {
        return new RestObject(STATUS_CODE_TIMEOUT, message, data);
    }
    
    /**
     * 生成访问对象
     * @param state state
     * @param message message
     * @param data data
     * @return obj
     */
    public static RestObject newRestObject(int state, String message, Object data) {
        return new RestObject(state, message, data);
    }
    
    /**
     * 生成访问对象
     * @param state state
     * @param message message
     * @return obj
     */
    public static RestObject newRestObject(int state, String message) {
        return new RestObject(state, message);
    }
    
    /**
     * 构造函数
     */
    public RestObject() {
    }
    
    /**
     * 构造函数
     * @param state state
     */
    public RestObject(int state) {
        this.state = state;
    }
    
    /**
     * 构造函数
     * @param state state
     * @param message message
     */
    public RestObject(int state, String message) {
        this.state = state;
        this.message = message;
    }
    
    /**
     * 构造函数
     * @param message message
     * @param state state
     * @param data data
     */
    public RestObject(int state, String message, Object data) {
        this.state = state;
        this.message = message;
        this.data = (null == data) ? "" : data;
    }
    
    public int getState() {
        return state;
    }
    public void setState(int state) {
        this.state = state;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }
    public Object getData() {
        return data;
    }
    public void setData(Object data) {
        this.data = data;
    }
    
}
